home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gigarom 1
/
Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso
/
FILES
/
HYP
/
C-D
/
DartmouthXCMDs.cpt
/
Dartmouth XCMDs Vol 1&2
/
card_11661.txt
< prev
next >
Wrap
Text File
|
1989-02-26
|
15KB
|
455 lines
-- card: 11661 from stack: in
-- bmap block id: 11899
-- flags: 0000
-- background id: 8327
-- name: LSC Utilities
----- HyperTalk script -----
on opencard
set the visible of field 1 to false -- background field
set the visible of card field "oh well" to false
set the scroll of card field 1 to 0
set the visible of button "put" to false
set the visible of button "get" to false
end opencard
on closecard
set the visible of field 1 to true
end closecard
-- part 5 (field)
-- low flags: 01
-- high flags: 2007
-- rect: left=18 top=32 right=290 bottom=486
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 20
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: XCMD Text
-- part 6 (button)
-- low flags: 00
-- high flags: 8003
-- rect: left=304 top=299 right=321 bottom=425
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Show LSC Source
----- HyperTalk script -----
on mouseUp
get the visible of card field "source"
set the visible of card field "source" to not it
if it is false then
set the name of me to "Hide LSC Source"
else
set the name of me to "Show LSC Source"
end if
end mouseUp
-- part 7 (field)
-- low flags: 81
-- high flags: 0007
-- rect: left=18 top=31 right=291 bottom=486
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 10
-- style flags: 0
-- line height: 13
-- part name: source
-- part 8 (field)
-- low flags: 80
-- high flags: 0002
-- rect: left=18 top=24 right=285 bottom=482
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: oh well
-- part 9 (button)
-- low flags: 80
-- high flags: 8003
-- rect: left=154 top=289 right=307 bottom=189
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Put
----- HyperTalk script -----
on mouseUp
-- You may have to change the parmater list to suit your configuration
-- NOTE: This button is a self contained operation of open, put,close.
-- You DO NOT have to open and close every time you get or put.
-- Just open once and start once, like when you open and close
-- your stack.
get SerialHandler("open","A",9600,8,none,1,"XON/XOFF")
if it is not empty then
put "Error: "&&it&&" (See script of "put" button)"
end if
get Serialhandler("put","A",the script of me)
if it is not empty then
put "Error: "&&it
end if
get Serialhandler("close","A")
end mouseUp
-- part 10 (button)
-- low flags: 80
-- high flags: 8003
-- rect: left=187 top=306 right=324 bottom=223
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Get
----- HyperTalk script -----
on mouseUp
-- You may have to change the parmater list to suit your configuration
-- NOTE: This button is a self contained operation of open, put,close.
-- You DO NOT have to open and close every time you get or put.
-- Just open once and start once, like when you open and close
-- your stack.
get SerialHandler("open","A",9600,8,none,1,"XON/XOFF")
set the visible of card field "got" to true
put empty into card field "got"
put "Click the mouse when done."
repeat while the mouse is up
get SerialHandler("get","A",60)
put it after card field "got"
end repeat
get SerialHandler("close","A")
set the visible of card field "got" to false
put empty into msg
end mouseUp
-- part 11 (field)
-- low flags: 80
-- high flags: 0007
-- rect: left=18 top=32 right=285 bottom=481
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: got
-- part contents for card part 5
----- text -----
LSC Utilities
Roger Brown
This is a collection of various C functions that are useful when creating XFCNs.
They are written in LightSpeed C.
Included are:
• Number of HyperCard Items : int NumHCitems(char *source)
Given a pointer to a source of HyperCard formatted items (comma delimited), return the
number of items in it.
• Get HyperCard Item : GetHCItem(char *inStr, int i, char *outStr)
Given a HyperCard item list (comma delimited) in string inStr, get item i and return it
as a string in outStr.
• Number of HyperCard Lines : int NumHCLines(char *source)
Given a pointer to a source of HyperCard formatted lines, such as a field, return the
number of lines in it.
• Get HyperCard Line : GetHCLine(int ine, char *source, char *dest)
Given a pointer to a source of lines (like a field), extract the requested line and return it
in string dest.
• Get HyperCard Expression : GetHCExpression(char *inStr, char *outStr)
Given a HyperCard expression in inString, return its value in outStr.
• String Contains : StrContains(char *target, char *test)
Given string test, return TRUE if it contains the string target.
• Get HyperCard Rectangle : GetCardRect(Rect *itsRect)
Get the rectangle of HyperCard's card window.
• Build a return result : ResultIs(XCmdBlockPtr paramPtr, char *theResult)
Given a C formatted string, build a return result structure for the given parameter block.
-- part contents for card part 7
----- text -----
/* HCLib1.0a1.c */
/* © Trustees of Dartmouth College */
/* written in LightSpeed C © Think Technologies, Inc */
/* by Roger Brown 7/7/88 Courseware Development group */
/* HyperCard XCMD support library */
#include "QuickDraw.h"
#include "FontMgr.h"
#include "EventMgr.h"
#include "WindowMgr.h"
#include "MenuMgr.h"
#include "MemoryMgr.h"
#include "ResourceMgr.h"
#include "ToolboxUtil.h"
#include "ControlMgr.h"
#include "DialogMgr.h"
#include "HyperXCmd.h"
#include "XCmdGlue.inc.c"
/* Get the number of HyperCard comma delimited items in string s. */
int NumHCItems(s)
char *s;
{
int c; /* character pointer */
int len; /* length of string */
int count; /* count of items found */
int j; /* item byte counter */
count = j = 0; /* initialize */
len = strlen(s); /* will look this far */
for (c=0;c<len;c++) { /* scan all characters */
if (s[c]==',') { /* found end of an item */
count = count + 1; /* bump item found counter */
j = 0; /* reset item scan counter */
}
else {
j++; /* bump item byte counter */
if (c==(len-1)) { /* last item, no comma */
count = count+1; /* this one counts, too */
break;
}
}
}
return count;
}
/* Get HyperCard comma delimited item i from item list string inStr. Return it in outStr */
/* item must be smaller than 255 characters */
GetHCItem(inStr,i,outStr)
char *inStr,*outStr;
int i;
{
int c; /* character pointer */
int len; /* length to scan */
int count; /* count of items found */
int j; /* item byte count */
Str255 temp; /* collect item here, hope its < 255 */
count = j = 0; /* initialize */
len = strlen(inStr); /* go this far, max */
for (c=0;c<len;c++) {
if (inStr[c]==',') { /* at an item boundary */
count = count + 1; /* bump counter */
if (count==i) break; /* if this is it, stop scanning */
j = 0; /* else start on the next item */
}
else {
temp[j] = inStr[c]; /* collect characters to return */
j++; /* go to next */
if (j==255) { /* sorry, too big to store */
strcpy(temp,"Error: Item > 255 characters.");
return;
}
if (c==(len-1)) { /* last item, no comma */
count = count+1;
break;
}
}
}
if (count < i) strcpy(outStr,"Error: item out of range"); /* no item there */
else {
temp[j] = 0; /* make it a C string */
strcpy(outStr,temp); /* move to output string */
}
return;
}
/* how many HyperCard lines in string source */
NumHCLines(source)
char *source;
{
int c; /* character counter */
int l; /* line counter */
int len;
len = strlen(source);
l = 0;
for (c=0;c<len;c++) { /* scan to desired line */
if (source[c]==13) l++;
}
if (source[c-1]!=13) l++; /* last line might not have CR */
return l;
}
/* get HyperCard line from source and return in dest */
GetHCLine(line,source,dest)
int line;
char *source,*dest;
{
int i; /* char counter before line */
int j; /* char cou,tner after line */
int c; /* line counter */
int len; /* length of source */
len = strlen(source); /* go this far, max */
c = 1; /* initialize */
i = 0;
while (c<line) { /* cycle to desired line */
if (source[i]==13) c++; /* bump line count */
i++;
if (i>len) { /* out of range */
strcpy(dest,"Error: Line out of range.");
return;
}
}
c = 0; /* at line, start transfer */
for (j=i;j<len;j++) {
*(dest+c) = source[j];
if (source[j]==13) break; /* line ended */
c++;
}
*(dest+c) = (char)0; /* make into a C string */
}
/* Given a HyperCard expression in inStr, return its value in outStr */
GetHCExpression(paramPtr,inStr,outStr)
XCmdBlockPtr paramPtr;
char *inStr;
Str255 *outStr;
{
Handle theResult; /* handle to the final result */
long len; /* length needed */
strcpy(outStr,inStr); /* cheat a little, use outStr as an intermediate */
CtoPstr(outStr); /* make it a P string */
theResult = EvalExpr(paramPtr,outStr); /* get its value from HC */
len = GetHandleSize(theResult); /* how long is it? */
BlockMove(*theResult,outStr,len); /* move the result into outStr */
DisposHandle(theResult); /* tidy up */
}
/* Return true if target string contains test string. Match is not case sensitive. */
char StrContains(target,test)
char *target,*test;
{
char ok;
int i;
char *j,*k;
int targetLen,testLen;
char go;
targetLen = strlen(target); /* scan this far, max */
testLen = strlen(test); /* look for this many matches */
for (i=0;i<targetLen;i++) {
j = target+i;
k = test;
while (toupper(*j)==toupper(*k)) { /* loop while they match */
j++;
k++;
if (k==(test+testLen)) return TRUE; /* got it */
}
}
return FALSE; /* no match */
}
/* Get the coordiates of the HyperCard card window */
GetCardRect(paramPtr,itsRect)
XCmdBlockPtr paramPtr;
Rect *itsRect;
{
Handle theResult;
long len,corner;
Str255 str,it;
int i; /* no comment */
strcpy(str,"the rect of card window");
CtoPstr(str);
theResult = EvalExpr(paramPtr,str);
len = GetHandleSize(theResult);
HLock(theResult);
BlockMove(*theResult,str,len);
HUnlock(theResult);
DisposHandle(theResult);
GetHCItem(str,1,it);
CtoPstr(it);
StringToNum(it,&corner);
itsRect->left = (int)corner;
GetHCItem(str,2,it);
CtoPstr(it);
StringToNum(it,&corner);
itsRect->top = (int)corner;
GetHCItem(str,3,it);
CtoPstr(it);
StringToNum(it,&corner);
itsRect->right = (int)corner;
GetHCItem(str,4,it);
CtoPstr(it);
StringToNum(it,&corner);
itsRect->bottom = (int)corner;
}
/* build a return result structure from a string */
ResultIs(paramPtr,theResult)
XCmdBlockPtr paramPtr;
char *theResult;
{
long len;
Handle resultHandle;
len = 1+strlen(theResult);
resultHandle = NewHandle(len);
BlockMove(theResult,*resultHandle,len);
paramPtr->returnValue = resultHandle;
}
-- part contents for card part 8
----- text -----
Alas, this demonstration will show you
nothing of interest unless you have a
serial device attached to your Mac. Like
an Imagewriter, or a terminal if you want
to get input.